package java_class_work.week07.jdbc;

import java_class_work.week07.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * @Auther: admin
 * @Date: 2022/10/25 11:11
 * @Description:
 */

public class Select {
    public static void main(String[] args) {
        String username = input();
        Connection con = JDBCUtils.getConnection();

        String sql = "select * from user where username = ?";
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = con.prepareStatement(sql);
            ps.setString(1, username);
            rs = ps.executeQuery();
            while (rs.next()){
                System.out.println(rs.getString("username")+"\t"+rs.getString("password"));
            }
            System.out.println("find rows" + rs.getRow());
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                rs.close();
                ps.close();
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            JDBCUtils.close();
        }
    }

    private static String input() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入想查询的账号：");
        return scanner.nextLine();
    }
}
